<section>
	<div class="tanchuang">
		<div class="tabchuang-mid">

			<p class="guanbi">
				<img src="/static/images/jia.png" alt="{$systemInfo.title}" />
			</p>
			<h3 class="gb-title">Let's Build Your Product</h3>
			<div class="gb-neirong">
				<p>Thank you for your interest in our products. Leave your email and message below to get the
					detailed data sheet and we will respond to your requirements shortly.</p>
			</div>
			<form action="/" class="" onsubmit="return false;" id="bottom_form1"  >
				<p><input type="text" placeholder="Name*" name="username" required />
					<span class="error-msg" data-error="username">Please enter your name</span>
				</p>
				<p><input type="email" placeholder="Email*" name="email" required />
					<span class="error-msg" data-error="email">Please enter a valid email address</span>
				</p>
				<p><input type="tel" placeholder="Phone*" name="phone" required />
					<span class="error-msg" data-error="phone">Please enter a valid phone number</span>
				</p>
				<p><input type="text" placeholder="Company*" name="company" required />
					<span class="error-msg" data-error="company">Please enter your company</span>
				</p>
				<p class="tea">
					<textarea rows="" cols="" placeholder="Message*" name="message" required></textarea>
					<span class="error-msg" data-error="message">Please enter a message</span>
				</p>
				<div>
					<input class="checkboxinput" name="privacy" type="checkbox" required />
					Standard fixtures can trap dust or emit particles, violating ISO 14644/GMP，
					<!-- <a href="/privacy-policy" target="_blank" class="ysxy">Privacy Agreement</a> -->
					<span class="error-msg" data-error="Checkbox">Please check the box</span>
				</div>
				<input type="button" class="stbtanc submitBtn1" value="Submit" />
			</form>
		</div>
	</div>

	<ul class="contact-footer active"> <!-- 右侧客服start -->
		<p><img src="/static/images/jia.png" alt="{$systemInfo.title}"> <img src="/static/images/hd.png" alt="{$systemInfo.title}" /> </p>
		<li class=""><p class="kf"><img src="/static/images/kf.png" alt="{$systemInfo.title}"></p></li>

		<li><a class="" href="https://wa.me/{$systemInfo.whatsapp_account}" title="" target="_blank"><img src="/static/images/whatsapp.png" alt="{$systemInfo.title}"></a>
			<span>{:strip_tags($systemInfo.whatsapp_account)}</span>
		</li>
		<li><a class="kf-youxiang" href="mailto:" title="" target="_blank"><img src="/static/images/email1.png" alt="{$systemInfo.title}"></a>
			<span>{$systemInfo.kf_email}</span>
		</li>

		<li class="topdiv"><img src="/static/images/top.png" alt="{$systemInfo.title}"></li>
	</ul> <!-- 右侧客服end -->
</section>
<script>
	// 添加邮箱验证函数
	function isValidEmail(email) {
		const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
		return emailRegex.test(email);
	}
	// 添加手机验证函数
	function isValidPhoneNumber(phone) {
		const phoneRegex = /^\d{8,}$/; // 至少 8 位数字
		return phoneRegex.test(phone);
	}

	$(".submitBtn1").click(function () {

		let params = {};
		let inputs = $("#bottom_form1 input");
		for (let i = 0; i < inputs.length; i++) {
			let input = inputs[i];
			if (input.hasAttribute('required') && $(input).val() === "") {
				alert('This input field is required, please fill in the content!');
				return false;
			}

			// 邮箱格式验证
			if ($(input).attr('name') === 'email') {
				const emailValue = $(input).val();
				if (!isValidEmail(emailValue)) {
					alert('Please enter a valid email address!');
					$(input).focus();
					return false;
				}
			}

			// 手机格式验证
			if ($(input).attr('name') === 'phone') {
				const phoneValue = $(input).val();
				if (!isValidPhoneNumber(phoneValue)) {
					alert('Phone number must be at least 8 digits!');
					$(input).focus();
					return false;
				}
			}

			// params['area_code'] = $('#bottom_form1 .footer-form-phone-select').text();
			params[$(input).attr('name')] = $(input).val();

		}
		params['message'] = $('#bottom_form1 textarea[name="message"]').val();

		// 正确验证隐私条款勾选框是否已选中
		if (!$('#bottom_form1 input[name="privacy"]').is(':checked')) {
			alert('Please check the privacy checkbox before submitting the form.');
			return false;
		}
		params['url'] = window.location.href
		var _this = this;
		$(_this).val('Submitting...').attr('disabled', true);
		$.post('feedback',
			params, function (res) {
				for (let i = 0; i < inputs.length; i++) {
					let input = inputs[i];
					$(input).val('');
				}
				$('.popupBox').hide();
				$(_this).val('Submit').attr('disabled', false);
				location.href = "/thanks.html";
			})
		});
</script>